org 0x7c00
[bits 16]
xor ax, ax ; eax = 0
; 初始化段寄存器, 段地址全部设为0
mov ax, cs
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax

mov sp, 0x7c00 
mov ax, 0xb879
mov gs, ax
mov ax, 0xb800 
mov es, ax 

;常量
Constant:
    delay equ 100000
;数据段
Data:
    count dw delay        
    flag db  1    
    color db 0x02       
    x dw 0                
    y dw 0       
    char db 'A'    
          
    
Showname:
    mov ah, 0x01 ;颜色
    mov al, '2'
    mov [gs:2 * 4], ax
    mov al, '2'
    mov [gs:2 * 5], ax
    mov al, '3'
    mov [gs:2 * 6], ax 
    mov al, '3'
    mov [gs:2 * 7], ax
    mov al, '6'
    mov [gs:2 * 8], ax
    mov al, '0'
    mov [gs:2 * 9], ax
    mov al, '0'
    mov [gs:2 * 10], ax
    mov al, '3'
    mov [gs:2 * 11], ax  
    mov al, 'D'
    mov [gs:2 * 12], ax  
    mov al, 'J'
    mov [gs:2 * 13], ax
    mov al, 'T'
    mov [gs:2 * 14], ax

IO:
    mov ah, 0
    int 0x16
    cmp al, 0x0D
    jz Clear1
    jmp IO


Clear1
    mov al, 'H'
    mov ah, 0x00
    mov bx, 0x0000
    mov cx, 0x1000
Clear2:
    mov [es: bx], ax 
    mov dx, cx
    cmp dx, bx
    je Loop1
    add bx, 2
    jmp Clear2
    
;延迟
Loop1:
    dec word[count]
    jnz Loop1
    
    mov word[count], delay
   
    mov al,1
    cmp al, byte[flag]
    jz RD
      
    mov al, 2
    cmp al, byte[flag]
    jz RU

    mov al, 3
    cmp al, byte[flag]
    jz LU
      
    mov al, 4
    cmp al, byte[flag]
    jz  LD

    jmp $

;右下
RD:
    inc word[x]
    inc word[y]
    mov bx, word[x]
    mov ax, 25
    cmp ax, bx
    jz  rd1
    
    mov bx, word[y]
    mov ax, 80
    cmp ax, bx
    jz  rd2
    
    jmp show

rd1:
    mov word[x], 23
    mov byte[flag], 2   
    jmp show
rd2:
    mov word[y], 78
    mov byte[flag], 4  
    jmp show

;右上
RU:
    dec word[x]
    inc word[y]
    mov bx, word[y]
    mov ax, 80
    cmp ax, bx
    jz  ru1
    
    mov bx, word[x]
    mov ax, 0
    cmp ax, bx
    jz  ru2
    
    jmp show

ru1:
    mov word[y], 78
    mov byte[flag], 3   
    jmp show
ru2:
    mov word[x], 1
    mov byte[flag], 1   
    jmp show
    
;左上
LU:
    dec word[x]
    dec word[y]
    mov bx, word[x]
    mov ax, 0
    cmp ax, bx
    jz  lu1

    mov bx,word[y]
    mov ax, -1
    cmp ax, bx
    jz  lu2
    
    jmp show

lu1:
    mov word[x], 1
    mov byte[flag], 4    
    jmp show
lu2:
    mov word[y], 1
    mov byte[flag], 2   
    jmp show

;左下
LD:
    inc word[x]
    dec word[y]
    mov bx, word[y]
    mov ax, -1
    cmp ax, bx
    jz  ld1
    
    mov bx, word[x]
    mov ax, 25
    cmp ax, bx
    jz  ld2
    
    jmp show

ld1:
    mov word[y], 1
    mov byte[flag], 1   
    jmp show
ld2:
    mov word[x], 23
    mov byte[flag], 3  
    jmp show

;显示字符
show:    
    xor ax, ax           
    mov ax, word[x]
    mov bx, 80
    mul bx
    add ax, word[y]
    mov bx, 2
    mul bx
    mov bx, ax
    mov ah, byte[color]      
    mov al, byte[char]    
    mov [es:bx], ax  
    
    inc byte[char]
    cmp byte[char], 'Z'+1
    jnz Loop2
    mov byte[char], 'A'

Loop2:  
    inc byte[color]
    jmp Loop1

times 510-($-$$) db 0
dw 0aa55h
